package com.bos.web.action;

import com.bos.domian.transit.TransitInfo;
import com.bos.service.TransitService;
import com.bos.web.BaseAction;
import com.opensymphony.xwork2.ActionContext;
import org.apache.commons.lang.StringUtils;
import org.apache.struts2.convention.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author misterWei
 * @create 2019年01月26号:17点18分
 * @mailbox mynameisweiyan@gmail.com
 *
 */
@ParentPackage("json-default")
@Actions
@Namespace("/")
@Controller
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)//多例的
public class TransitAction extends BaseAction<TransitInfo> {

    private String wayBillIds;

    public void setWayBillIds(String wayBillIds) {
        this.wayBillIds = wayBillIds;
    }
    @Autowired
    private TransitService transitService;
    @Action(value = "transitJojnWayBill",results = {@Result(name = "success",type = "json")})
    public String transitJojnWayBillSave(){
        Map<String,Object> resultMap = new HashMap<>(10);
        //再次判断空数据
        if (StringUtils.isEmpty(wayBillIds)) {
            resultMap.put("result",false);
            resultMap.put("msg","暂无运单数据！");
        }else {
            try {
                transitService.transitJojnWayBillSave(wayBillIds);
                resultMap.put("result",true);
                resultMap.put("msg","运单已中转！");
            } catch (Exception e) {
                resultMap.put("result",false);
                resultMap.put("msg",e.getMessage());
            }
        }
        ActionContext.getContext().getValueStack().push(resultMap);
        return SUCCESS;
    }
    @Action(value = "transit_findAll",results = {@Result(name = "success",type = "json")})
    public String transitFindAll(){
      List<TransitInfo> transitInfoList = transitService.findAll();
    ActionContext.getContext().getValueStack().push(transitInfoList);
        return SUCCESS;
    }
}
